﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace Aandelendelen.Caching
{
	public class CacheKey
	{
		public CacheDependency CacheDependency { get; set; }
		public int SecondsBeforeInvalidate { get; set; }
		public ICacheable ObjectToCache;

		public CacheKey()
		{
			SecondsBeforeInvalidate = 0;
			ObjectToCache = null;
			CacheDependency = null;
		}

		public void CacheThis(string cacheKey)
		{
			if (SecondsBeforeInvalidate == 0)
				HttpContext.Current.Cache.Insert(cacheKey, ObjectToCache, CacheDependency);
			else
				HttpContext.Current.Cache.Insert(cacheKey, ObjectToCache, CacheDependency, DateTime.Now.AddSeconds(SecondsBeforeInvalidate), Cache.NoSlidingExpiration);

		}

	}
}